import requests
import re


def main(url):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'}
    r = requests.get(url, headers=headers)
    html = r.text
    # print(html)
    pat = '<code.*?>(.*?)</code>'
    # pat = '<pre.*?>(.*?)</pre>'
    re_r = code_html = re.compile(pat, re.S).findall(html)
    change_dict = {'&lt;': '<', '&gt;': '>', '&#61;': '=', '&#34;': '"', '&#64;': '@', '&#43;': '+', '&#xff0c;': '，', '&amp;': '&', '&#39;': '\''}
    ele_pat = '(<.*?>)'
    for code_html in re_r:
        for k in change_dict:
            code_html = str(code_html).replace(k, change_dict[k])
        re_r = re.compile(ele_pat, re.S).findall(code_html)
        for r_falg in re_r:
            code_html = code_html.replace(r_falg, '')
        print(code_html)
        print('')
        print('-----------------------------------------------------')
        print('')


if __name__ == '__main__':
    u = 'https://blog.csdn.net/weixin_30603633/article/details/96302754'
    u = 'https://blog.csdn.net/weixin_52851967/article/details/123183128'
    u = input('输入CSDN页面地址：')
    main(u)
